<?php
require_once('Xml/Info/Abstract.php');

class Xml_Info_Provider extends Xml_Info_Abstract {
    public function getRssInfo() {
       // $query = "select * from news where `isok` = 1 and date_format(`edittime`, '%Y-%m') = date_format(now(), '%Y-%m')";
   // $query = "select * from news where `isok` = 1 order by `senttime` ASC";
 $query = "select * from news where `isok` = 1 AND DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(`edittime`)  order by `senttime` ASC";
        $rows = $this->_fetchAll($query);
        $items = array();
        foreach($rows as $row) {
            // @todo: 此处存在与$_SERVER耦合，如何消除? --john.shen
            $item = array(
                    'link'      => htmlentities(sprintf('http://%s/%s?id=%d', $_SERVER['HTTP_HOST'], get_article_page_url_by_type($row['lb']), $row['id'])),
                    'url'       => htmlentities(sprintf('http://%s/upfiles/%s', $_SERVER['HTTP_HOST'], $row['images1'])),
                    'pubDate'   => date('D, d M Y H:m:s', strtotime($row['senttime'])).' GMT',
                    'img'   => sprintf('http://%s/upfiles/%s', $_SERVER['HTTP_HOST'], $row['images1']),
                    'content'   => utf8substr(strip_tags(abc($row['content'])), 0, constant('MAX_SUMMARY_ARTICLE_LEN'))
                   );

            $items[] = array_merge($row, $item);
        }
        $header = array(
                'title'         => '[Bios Monthly] The Lifestyle Brand',
                'link'          => 'http://'.$_SERVER['HTTP_HOST'],
                'description'   => '這裡是一個充滿欲望與逸樂的基地，提供你有觀點又有趣的新鮮文章與資訊。我們有面向超廣的寫手群，關注城市裡的大小事，從城市的內涵、長相到想像，我們無所不包。',
                'pubDate'       => date('D, d M Y H:m:s').' GMT',
                'copyright'     => date('Y').' Bios MONTHLY, ALL RIGHTS RESERVED',
                'webMaster'     => 'dragon.iphone@gmail.com(Dragon)',
                'language'      => 'zh-TW',
                'doc'           => 'http://'.$_SERVER['HTTP_HOST'].'/rss',
                'image_title'   => '[Bios Monthly] The Lifestyle Brand',
                'image_link'    => 'http://'.$_SERVER['HTTP_HOST'],
                'image_url'     => 'http://'.$_SERVER['HTTP_HOST'].'/images/logo.png');
        return new Xml_Info_Entity($items, $header);
    }

    public function getSitemapInfo() {
       // $query = "select * from news where `isok` = 1 and date_format(`senttime`, '%Y-%m') = date_format(now(), '%Y-%m')";
         //$query = "select * from news where `isok` = 1 order by `senttime` ASC";
     $query = "select * from news where `isok` = 1 AND DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(`edittime`)  order by `senttime` ASC";
       $rows = $this->_fetchAll($query); 
        $items = array();
        foreach($rows as $row) {
            $item = array(
                    'loc'       => htmlentities(sprintf('http://%s/%s?id=%d', $_SERVER['HTTP_HOST'], get_article_page_url_by_type($row['lb']), $row['id'])),
                    'lastmod'   => date('Y-m-d', strtotime($row['senttime'])),
                    'freq'      => 'daily'
                    );
            $items[] = $item;
        }
        return new Xml_Info_Entity($items);
    }
}
